diff options
author | Santo Cariotti <santo@dcariotti.me> | 2024-06-04 14:11:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-04 14:11:32 +0200 |
commit | 1c8761901b26c0be4d61f3aed5ec0495a558a0e7 (patch) | |
tree | be3177edeaf93cbd57e49f7067418bc8ef0dfdd3 /src/Python3Parser.g4 | |
parent | 663b99a971f8dd7f7776fe3647f24ce728b3d434 (diff) |
Refactor using package `com.clp.project` (#1)
Co-authored-by: geno <gabriele.genovese2@studio.unibo.it>
Diffstat (limited to 'src/Python3Parser.g4')
-rw-r--r-- | src/Python3Parser.g4 | 181 |
1 files changed, 0 insertions, 181 deletions
diff --git a/src/Python3Parser.g4 b/src/Python3Parser.g4 deleted file mode 100644 index c145e56..0000000 --- a/src/Python3Parser.g4 +++ /dev/null @@ -1,181 +0,0 @@ -/* - La grammatica di Python si trova a - https://docs.python.org/3/reference/grammar.html - - Questa e` stata elaborata da Bart Kiers, bart@big-o.nl - e si trova a https://github.com/bkiers/python3-parser - - Semplificata ai fini del corso di CLP -- Marco Bertoni, Cosimo Laneve -*/ - -// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false -// $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging - -parser grammar Python3Parser; - -options { - superClass = Python3ParserBase; - tokenVocab = Python3Lexer; -} - -root - : NEWLINE* (simple_stmts | compound_stmt)* EOF - ; - -simple_stmts - : simple_stmt (';' simple_stmt)* ';'? NEWLINE - ; - -compound_stmt - : if_stmt - | while_stmt - | for_stmt - | funcdef - ; - -simple_stmt - : assignment - | expr - | return_stmt - | import_stm - ; - -assignment - : exprlist augassign exprlist - ; - -return_stmt - : 'return' exprlist? - ; - -import_stm - : 'import' dotted_name ('as' NAME)? - | 'from' dotted_name 'import' (NAME (',' NAME)* | '*') - ; - -dotted_name - : NAME ('.' NAME)* - ; - -funcdef - : 'def' NAME '(' paramlist? ')' ':' block - ; - -paramlist - : paramdef ('=' expr)? (',' paramdef ('=' expr)?)* - ; - -paramdef - : NAME (':' expr)? - ; - -augassign - : '=' - | '+=' - | '-=' - | '*=' - | '@=' - | '/=' - | '%=' - | '&=' - | '|=' - | '^=' - | '<<=' - | '>>=' - | '**=' - | '//=' - ; - -if_stmt - : 'if' expr ':' block ('elif' expr ':' block)* ('else' ':' block)? - ; - -while_stmt - : 'while' expr ':' block ('else' ':' block)? - ; - -for_stmt - : 'for' exprlist ':' block ('else' ':' block)? - ; - -block - : simple_stmts - | NEWLINE INDENT (simple_stmts | compound_stmt)+ DEDENT - ; - -comp_op - : '<' - | '>' - | '==' - | '>=' - | '<=' - | '<>' - | '!=' - | 'in' - | 'not' 'in' - | 'is' - | 'is' 'not' - ; - -expr - : atom trailer* - | expr '**' expr - | ('+' | '-' | '~')+ expr - | expr ('*' | '@' | '/' | '%' | '//') expr - | expr ('+' | '-') expr - | expr ('<<' | '>>') expr - | expr '&' expr - | expr '^' expr - | expr '|' expr - | 'not' expr - | expr comp_op expr - | expr 'and' expr - | expr 'or' expr - | expr 'if' expr 'else' expr - ; -atom - : '(' testlist_comp? ')' - | '[' testlist_comp? ']' - | '{' testlist_comp? '}' - | NAME - | NUMBER - | STRING+ - | '...' - | 'None' - | 'True' - | 'False' - ; - -testlist_comp : expr (comp_for | (',' expr)* ','?) - ; -trailer - : '(' arglist? ')' - | '[' expr (',' expr)* ','? ']' - | '.' NAME - | '[' expr? ':' expr? (':' expr? )? ']' - ; - -exprlist - : expr (',' expr )* ','? - ; - -arglist - : argument (',' argument)* ','? - ; - -argument - : expr comp_for? | expr '=' expr - ; - -comp_iter - : comp_for - | comp_if - ; - -comp_for - : 'for' exprlist 'in' expr comp_iter? - ; - -comp_if - : 'if' expr comp_iter? - ;
\ No newline at end of file |