improvements on line no

This commit is contained in:
ridethepig 2023-03-22 16:34:16 +00:00
parent e07f9769e0
commit d2490af747
3 changed files with 25 additions and 17 deletions

View File

@ -154,6 +154,7 @@
/* all other binary operations are left-associative /* all other binary operations are left-associative
* assignment is right-associative, * assignment is right-associative,
* three comparison operations do not associate.*/ * three comparison operations do not associate.*/
%nonassoc LETEXPR
%right ASSIGN %right ASSIGN
%left NOT %left NOT
%nonassoc '<' LE '=' %nonassoc '<' LE '='
@ -163,7 +164,6 @@
%nonassoc '~' %nonassoc '~'
%nonassoc '@' %nonassoc '@'
%nonassoc '.' %nonassoc '.'
%left LETEXPR
%% %%
@ -185,12 +185,14 @@
/* If no parent is specified, the class inherits from the Object class. */ /* If no parent is specified, the class inherits from the Object class. */
class : CLASS TYPEID '{' feature_list '}' ';' class : CLASS TYPEID '{' feature_list '}' ';'
{ $$ = class_($2,idtable.add_string("Object"),$4, { $$ = class_($2,idtable.add_string("Object"),$4,stringtable.add_string(curr_filename)); }
stringtable.add_string(curr_filename)); } | CLASS TYPEID '{' '}' ';'
{ $$ = class_($2,idtable.add_string("Object"),nil_Features(),stringtable.add_string(curr_filename)); }
| CLASS TYPEID INHERITS TYPEID '{' feature_list '}' ';' | CLASS TYPEID INHERITS TYPEID '{' feature_list '}' ';'
{ $$ = class_($2,$4,$6,stringtable.add_string(curr_filename)); } { $$ = class_($2,$4,$6,stringtable.add_string(curr_filename)); }
| CLASS TYPEID INHERITS TYPEID '{' '}' ';' | CLASS TYPEID INHERITS TYPEID '{' '}' ';'
{ $$ = class_($2,$4,nil_Features(),stringtable.add_string(curr_filename)); } { $$ = class_($2,$4,nil_Features(),stringtable.add_string(curr_filename)); }
| CLASS error '{' error '}' ';'
; ;
/* Feature list may be empty, but no empty features in list. */ /* Feature list may be empty, but no empty features in list. */
@ -202,6 +204,11 @@
feature : OBJECTID ':' TYPEID feature : OBJECTID ':' TYPEID
/* Use no expr where optional expression omitted*/ /* Use no expr where optional expression omitted*/
/* The lineno for `no_expr` is somehow different from standard parser(std parser sets it to 0),
* if you want to perfektly conform to that, the code below provides a workaround
* { auto _lineno = @$; SET_NODELOC(0); auto _no_expr = no_expr(); SET_NODELOC(_lineno); $$ = attr($1, $3, _no_expr); }
* or you can modify cool-tree.h:754, manually override line_number to 0
*/
{ $$ = attr($1, $3, no_expr()); } { $$ = attr($1, $3, no_expr()); }
| OBJECTID ':' TYPEID ASSIGN expression | OBJECTID ':' TYPEID ASSIGN expression
{ $$ = attr($1, $3, $5); } { $$ = attr($1, $3, $5); }
@ -269,37 +276,37 @@
* there could be 2 interpretations: (let id1:T1 in expression).f() | let id1:T1 in (expression.f()) * there could be 2 interpretations: (let id1:T1 in expression).f() | let id1:T1 in (expression.f())
* This should be specified to dis-ambiguite * This should be specified to dis-ambiguite
* *
* The manual says, the expr extends as far as possible * The manual says, the expr extends as far as possible, so we just set the lowest precedence
*/ */
| LET nested_let | LET nested_let
{ $$ = $2; } { $$ = $2; }
| CASE expression OF case_list ESAC | CASE expression OF case_list ESAC
{ $$ = typcase($2, $4); } { $$ = typcase($2, $4); }
| NEW TYPEID | NEW TYPEID
{ $$ = new_($2); } { SET_NODELOC(@2); $$ = new_($2); }
| ISVOID expression | ISVOID expression
{ $$ = isvoid($2); } { SET_NODELOC(@2); $$ = isvoid($2); }
/* the rules below need precedence specification */ /* the rules below need precedence specification */
| expression '+' expression | expression '+' expression
{ $$ = plus($1, $3); } { SET_NODELOC(@3); $$ = plus($1, $3); }
| expression '-' expression | expression '-' expression
{ $$ = sub($1, $3); } { SET_NODELOC(@3); $$ = sub($1, $3); }
| expression '*' expression | expression '*' expression
{ $$ = mul($1, $3); } { SET_NODELOC(@3); $$ = mul($1, $3); }
| expression '/' expression | expression '/' expression
{ $$ = divide($1, $3); } { SET_NODELOC(@3); $$ = divide($1, $3); }
| '~' expression | '~' expression
{ $$ = neg($2); } { SET_NODELOC(@2); $$ = neg($2); }
| expression '<' expression | expression '<' expression
{ $$ = lt($1, $3); } { SET_NODELOC(@3); $$ = lt($1, $3); }
| expression LE expression | expression LE expression
{ $$ = leq($1, $3); } { SET_NODELOC(@3); $$ = leq($1, $3); }
| expression '=' expression | expression '=' expression
{ $$ = eq($1, $3); } { SET_NODELOC(@3); $$ = eq($1, $3); }
| NOT expression | NOT expression
{ $$ = comp($2); } { SET_NODELOC(@2); $$ = comp($2); }
| '(' expression ')' | '(' expression ')'
{ $$ = $2; } { SET_NODELOC(@2); $$ = $2; }
| OBJECTID | OBJECTID
{ $$ = object($1); } { $$ = object($1); }
| INT_CONST | INT_CONST

View File

@ -1,2 +1,2 @@
#!/bin/csh -f #!/bin/bash -f
./lexer $* | ./parser $* ./lexer $* | ./parser $*

View File

@ -752,6 +752,7 @@ class no_expr_class : public Expression_class {
protected: protected:
public: public:
no_expr_class() { no_expr_class() {
line_number = 0;
} }
Expression copy_Expression(); Expression copy_Expression();
void dump(ostream& stream, int n); void dump(ostream& stream, int n);