Commit 66f4532f authored by lyz's avatar lyz

initial lab1

parents
cmake_minimum_required( VERSION 3.8 )
project(CMINUSF)
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -std=c99")
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
SET(CMAKE_CXX_FLAGS_ASAN "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined -fsanitize=address")
set(default_build_type "Debug")
if(NOT(CMAKE_BUILD_TYPE_SHADOW STREQUAL CMAKE_BUILD_TYPE))
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}'")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
else()
message(STATUS "Building in ${CMAKE_BUILD_TYPE} mode")
endif()
set(CMAKE_BUILD_TYPE_SHADOW ${CMAKE_BUILD_TYPE} CACHE STRING "used to detect changes in build type" FORCE)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(FLEX REQUIRED)
find_package(BISON REQUIRED)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
llvm_map_components_to_libnames(
llvm_libs
support
core
)
INCLUDE_DIRECTORIES(
include
include/cminusfc
include/common
include/lightir
${LLVM_INCLUDE_DIRS}
)
add_definitions(${LLVM_DEFINITIONS})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_BINARY_DIR})
add_subdirectory(src)
# 简介
本仓库为 USTC 编译原理和技术 2024 的课程实验仓库。在本学期的编译实验中,你们将构建一个从词法分析器开始到后端代码生成的JIANMU编译器。
你们需要 fork 此 repo 到自己的仓库下,随后在自己的仓库中完成实验。
## 测试脚本使用方法
eval_phase1.sh: 测试phase1 词法分析器+语法分析器部分
-all: 测试所有测试集 (easy, normal, hard, testcases_general)
easy/normal/hard/testcases_general + yes/no/verbose: 测试单个测试集
yes: 使用diff判断正确性
no: 不使用diff判断正确性
verbose: 使用diff判断正确性,并看到更详细的输出
eval_phase2.sh: 测试phase2 syntax_tree -> ast 部分
使用方法与eval_phase1.sh完全相同, 会自动跳过生成syntax_tree fail的样例
\ No newline at end of file
#pragma once
extern "C" {
#include "syntax_tree.h"
extern syntax_tree *parse(const char *input);
}
#include <memory>
#include <string>
#include <vector>
enum CminusType { TYPE_INT, TYPE_FLOAT, TYPE_VOID };
enum RelOp {
// <=
OP_LE,
// <
OP_LT,
// >
OP_GT,
// >=
OP_GE,
// ==
OP_EQ,
// !=
OP_NEQ
};
enum AddOp {
// +
OP_PLUS,
// -
OP_MINUS
};
enum MulOp {
// *
OP_MUL,
// /
OP_DIV
};
class AST;
struct ASTNode;
struct ASTProgram;
struct ASTDeclaration;
struct ASTNum;
struct ASTVarDeclaration;
struct ASTFunDeclaration;
struct ASTParam;
struct ASTCompoundStmt;
struct ASTStatement;
struct ASTExpressionStmt;
struct ASTSelectionStmt;
struct ASTIterationStmt;
struct ASTReturnStmt;
struct ASTFactor;
struct ASTExpression;
struct ASTVar;
struct ASTAssignExpression;
struct ASTSimpleExpression;
struct ASTAdditiveExpression;
struct ASTTerm;
struct ASTCall;
class ASTVisitor;
class AST {
public:
AST() = delete;
AST(syntax_tree *);
AST(AST &&tree) {
root = tree.root;
tree.root = nullptr;
};
ASTProgram *get_root() { return root.get(); }
void run_visitor(ASTVisitor &visitor);
private:
ASTNode *transform_node_iter(syntax_tree_node *);
std::shared_ptr<ASTProgram> root = nullptr;
};
struct ASTNode {
virtual void accept(ASTVisitor &) = 0;
virtual ~ASTNode() = default;
};
struct ASTProgram : ASTNode {
virtual void accept(ASTVisitor &) override final;
virtual ~ASTProgram() = default;
std::vector<std::shared_ptr<ASTDeclaration>> declarations;
};
struct ASTDeclaration : ASTNode {
virtual ~ASTDeclaration() = default;
CminusType type;
std::string id;
};
struct ASTFactor : ASTNode {
virtual ~ASTFactor() = default;
};
struct ASTNum : ASTFactor {
virtual void accept(ASTVisitor &) override final;
CminusType type;
union {
int i_val;
float f_val;
};
};
struct ASTVarDeclaration : ASTDeclaration {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTNum> num;
};
struct ASTFunDeclaration : ASTDeclaration {
virtual void accept(ASTVisitor &) override final;
std::vector<std::shared_ptr<ASTParam>> params;
std::shared_ptr<ASTCompoundStmt> compound_stmt;
};
struct ASTParam : ASTNode {
virtual void accept(ASTVisitor &) override final;
CminusType type;
std::string id;
// true if it is array param
bool isarray;
};
struct ASTStatement : ASTNode {
virtual ~ASTStatement() = default;
};
struct ASTCompoundStmt : ASTStatement {
virtual void accept(ASTVisitor &) override final;
std::vector<std::shared_ptr<ASTVarDeclaration>> local_declarations;
std::vector<std::shared_ptr<ASTStatement>> statement_list;
};
struct ASTExpressionStmt : ASTStatement {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTExpression> expression;
};
struct ASTSelectionStmt : ASTStatement {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTExpression> expression;
std::shared_ptr<ASTStatement> if_statement;
// should be nullptr if no else structure exists
std::shared_ptr<ASTStatement> else_statement;
};
struct ASTIterationStmt : ASTStatement {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTExpression> expression;
std::shared_ptr<ASTStatement> statement;
};
struct ASTReturnStmt : ASTStatement {
virtual void accept(ASTVisitor &) override final;
// should be nullptr if return void
std::shared_ptr<ASTExpression> expression;
};
struct ASTExpression : ASTFactor {};
struct ASTAssignExpression : ASTExpression {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTVar> var;
std::shared_ptr<ASTExpression> expression;
};
struct ASTSimpleExpression : ASTExpression {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTAdditiveExpression> additive_expression_l;
std::shared_ptr<ASTAdditiveExpression> additive_expression_r;
RelOp op;
};
struct ASTVar : ASTFactor {
virtual void accept(ASTVisitor &) override final;
std::string id;
// nullptr if var is of int type
std::shared_ptr<ASTExpression> expression;
};
struct ASTAdditiveExpression : ASTNode {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTAdditiveExpression> additive_expression;
AddOp op;
std::shared_ptr<ASTTerm> term;
};
struct ASTTerm : ASTNode {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTTerm> term;
MulOp op;
std::shared_ptr<ASTFactor> factor;
};
struct ASTCall : ASTFactor {
virtual void accept(ASTVisitor &) override final;
std::string id;
std::vector<std::shared_ptr<ASTExpression>> args;
};
class ASTVisitor {
public:
virtual void visit(ASTProgram &) = 0;
virtual void visit(ASTNum &) = 0;
virtual void visit(ASTVarDeclaration &) = 0;
virtual void visit(ASTFunDeclaration &) = 0;
virtual void visit(ASTParam &) = 0;
virtual void visit(ASTCompoundStmt &) = 0;
virtual void visit(ASTExpressionStmt &) = 0;
virtual void visit(ASTSelectionStmt &) = 0;
virtual void visit(ASTIterationStmt &) = 0;
virtual void visit(ASTReturnStmt &) = 0;
virtual void visit(ASTAssignExpression &) = 0;
virtual void visit(ASTSimpleExpression &) = 0;
virtual void visit(ASTAdditiveExpression &) = 0;
virtual void visit(ASTVar &) = 0;
virtual void visit(ASTTerm &) = 0;
virtual void visit(ASTCall &) = 0;
};
class ASTPrinter : public ASTVisitor {
public:
virtual void visit(ASTProgram &) override final;
virtual void visit(ASTNum &) override final;
virtual void visit(ASTVarDeclaration &) override final;
virtual void visit(ASTFunDeclaration &) override final;
virtual void visit(ASTParam &) override final;
virtual void visit(ASTCompoundStmt &) override final;
virtual void visit(ASTExpressionStmt &) override final;
virtual void visit(ASTSelectionStmt &) override final;
virtual void visit(ASTIterationStmt &) override final;
virtual void visit(ASTReturnStmt &) override final;
virtual void visit(ASTAssignExpression &) override final;
virtual void visit(ASTSimpleExpression &) override final;
virtual void visit(ASTAdditiveExpression &) override final;
virtual void visit(ASTVar &) override final;
virtual void visit(ASTTerm &) override final;
virtual void visit(ASTCall &) override final;
void add_depth() { depth += 2; }
void remove_depth() { depth -= 2; }
private:
int depth = 0;
};
#ifndef LOGGING_HPP
#define LOGGING_HPP
#include <iostream>
#include <sstream>
#include <cstdlib>
enum LogLevel
{
DEBUG = 0,
INFO,
WARNING,
ERROR
};
struct LocationInfo
{
LocationInfo(std::string file, int line, const char *func) : file_(file), line_(line), func_(func) {}
~LocationInfo() = default;
std::string file_;
int line_;
const char *func_;
};
class LogStream;
class LogWriter;
class LogWriter
{
public:
LogWriter(LocationInfo location, LogLevel loglevel)
: location_(location), log_level_(loglevel)
{
char *logv = std::getenv("LOGV");
if (logv)
{
std::string string_logv = logv;
env_log_level = std::stoi(logv);
}
else
{
env_log_level = 4;
}
};
void operator<(const LogStream &stream);
private:
void output_log(const std::ostringstream &g);
LocationInfo location_;
LogLevel log_level_;
int env_log_level;
};
class LogStream
{
public:
template <typename T>
LogStream &operator<<(const T &val) noexcept
{
sstream_ << val;
return *this;
}
friend class LogWriter;
private:
std::stringstream sstream_{};
};
std::string level2string(LogLevel level);
std::string get_short_name(const char *file_path);
#define __FILESHORTNAME__ get_short_name(__FILE__)
#define LOG_IF(level) \
LogWriter(LocationInfo(__FILESHORTNAME__, __LINE__, __FUNCTION__), level) < LogStream()
#define LOG(level) LOG_##level
#define LOG_DEBUG LOG_IF(DEBUG)
#define LOG_INFO LOG_IF(INFO)
#define LOG_WARNING LOG_IF(WARNING)
#define LOG_ERROR LOG_IF(ERROR)
#endif
#ifndef __SYNTAXTREE_H__
#define __SYNTAXTREE_H__
#include <stdio.h>
#define SYNTAX_TREE_NODE_NAME_MAX 30
struct _syntax_tree_node {
struct _syntax_tree_node * parent;
struct _syntax_tree_node * children[10];
int children_num;
char name[SYNTAX_TREE_NODE_NAME_MAX];
};
typedef struct _syntax_tree_node syntax_tree_node;
syntax_tree_node * new_anon_syntax_tree_node();
syntax_tree_node * new_syntax_tree_node(const char * name);
int syntax_tree_add_child(syntax_tree_node * parent, syntax_tree_node * child);
void del_syntax_tree_node(syntax_tree_node * node, int recursive);
struct _syntax_tree {
syntax_tree_node * root;
};
typedef struct _syntax_tree syntax_tree;
syntax_tree* new_syntax_tree();
void del_syntax_tree(syntax_tree * tree);
void print_syntax_tree(FILE * fout, syntax_tree * tree);
#endif /* SyntaxTree.h */
add_subdirectory(parser)
add_subdirectory(common)
add_subdirectory(logging)
add_subdirectory(cminusfc)
add_executable(
cminusfc
main.cpp
)
target_link_libraries(
cminusfc
common
syntax
stdc++fs
)
install(
TARGETS cminusfc
RUNTIME DESTINATION bin
)
#include "ast.hpp"
#include <filesystem>
#include <iostream>
#include <string>
using std::string;
using std::operator""s;
struct Config
{
string exe_name; // compiler exe name
std::filesystem::path input_file;
std::filesystem::path output_file;
bool emitast{false};
Config(int argc, char **argv) : argc(argc), argv(argv)
{
parse_cmd_line();
check();
}
private:
int argc{-1};
char **argv{nullptr};
void parse_cmd_line();
void check();
// print helper infomation and exit
void print_help() const;
void print_err(const string &msg) const;
};
int main(int argc, char **argv)
{
Config config(argc, argv);
auto syntax_tree = parse(config.input_file.c_str());
auto ast = AST(syntax_tree);
ASTPrinter printer;
ast.run_visitor(printer);
return 0;
}
void Config::parse_cmd_line()
{
exe_name = argv[0];
for (int i = 1; i < argc; ++i)
{
if (argv[i] == "-h"s || argv[i] == "--help"s)
{
print_help();
}
else if (argv[i] == "-o"s)
{
if (output_file.empty() && i + 1 < argc)
{
output_file = argv[i + 1];
i += 1;
}
else
{
print_err("bad output file");
}
}
else if (argv[i] == "-emit-ast"s)
{
emitast = true;
}
else
{
if (input_file.empty())
{
input_file = argv[i];
}
else
{
string err =
"unrecognized command-line option \'"s + argv[i] + "\'"s;
print_err(err);
}
}
}
}
void Config::check()
{
if (input_file.empty())
{
print_err("no input file");
}
if (input_file.extension() != ".cminus")
{
print_err("file format not recognized");
}
if (output_file.empty())
{
output_file = input_file.stem();
}
}
void Config::print_help() const
{
std::cout << "Usage: " << exe_name
<< " [-h|--help] [-o <target-file>] [-mem2reg] [-emit-llvm] [-S] "
"<input-file>"
<< std::endl;
exit(0);
}
void Config::print_err(const string &msg) const
{
std::cout << exe_name << ": " << msg << std::endl;
exit(-1);
}
add_library(common STATIC
syntax_tree.c
ast.cpp
logging.cpp
)
target_link_libraries(common)
This diff is collapsed.
#include "logging.hpp"
void LogWriter::operator<(const LogStream &stream) {
std::ostringstream msg;
msg << stream.sstream_.rdbuf();
output_log(msg);
}
void LogWriter::output_log(const std::ostringstream &msg) {
if (log_level_ >= env_log_level)
std::cout << "[" << level2string(log_level_) << "] "
<< "(" << location_.file_
<< ":" << location_.line_
<< "L "<< location_.func_<<")"
<< msg.str() << std::endl;
}
std::string level2string(LogLevel level) {
switch (level)
{
case DEBUG:
return "DEBUG";
case INFO:
return "INFO";
case WARNING:
return "WARNING";
case ERROR:
return "ERROR";
default:
return "";
}
}
std::string get_short_name(const char * file_path) {
std::string short_file_path = file_path;
int index = short_file_path.find_last_of('/');
return short_file_path.substr(index+1);
}
#include <stdlib.h>
#include <string.h>
#include "syntax_tree.h"
syntax_tree_node * new_syntax_tree_node(const char * name)
{
syntax_tree_node * new_node = (syntax_tree_node *)malloc(sizeof(syntax_tree_node));
if (name)
strncpy(new_node->name, name, SYNTAX_TREE_NODE_NAME_MAX);
else
new_node->name[0] = '\0';
new_node->children_num = 0;
return new_node;
}
int syntax_tree_add_child(syntax_tree_node * parent, syntax_tree_node * child)
{
if (!parent || !child) return -1;
parent->children[parent->children_num++] = child;
return parent->children_num;
}
void del_syntax_tree_node(syntax_tree_node * node, int recursive)
{
if (!node) return;
int i;
if (recursive) {
for (i = 0; i < node->children_num; i++) {
del_syntax_tree_node(node->children[i], 1);
}
}
free(node);
}
syntax_tree * new_syntax_tree()
{
return (syntax_tree *)malloc(sizeof(syntax_tree));
}
void del_syntax_tree(syntax_tree * tree)
{
if (!tree) return;
if (tree->root) {
del_syntax_tree_node(tree->root, 1);
}
free(tree);
}
void print_syntax_tree_node(FILE * fout, syntax_tree_node * node, int level)
{
// assume fout valid now
// check if "node" empty pointer
if (!node) return;
// print myself
int i;
for (i = 0; i < level; i++) {
fprintf(fout, "| ");
}
fprintf(fout, ">--%s %s\n", (node->children_num ? "+" : "*"), node->name);
for (i = 0; i < node->children_num; i++) {
print_syntax_tree_node(fout, node->children[i], level + 1);
}
}
void print_syntax_tree(FILE * fout, syntax_tree * tree)
{
if (!fout) return;
print_syntax_tree_node(fout, tree->root, 0);
}
add_executable(test_ast test_ast.cpp)
add_executable(test_logging test_logging.cpp)
target_link_libraries(test_ast syntax common)
target_link_libraries(test_logging common)
install(
TARGETS test_logging
RUNTIME DESTINATION bin
)
install(
TARGETS test_ast
RUNTIME DESTINATION bin
)
#include "ast.hpp"
#include <iostream>
int main(int argc, char **argv) {
if (argc != 2) {
std::cout << "usage: " << argv[0] << " <cminus_file>" << std::endl;
} else {
auto s = parse(argv[1]);
auto a = AST(s);
auto printer = ASTPrinter();
a.run_visitor(printer);
}
return 0;
}
#include "logging.hpp"
// 引入头文件
int main() {
LOG(DEBUG) << "This is DEBUG log item.";
// 使用关键字LOG,括号中填入要输出的日志等级
// 紧接着就是<<以及日志的具体信息,这一步就跟使用std::cout一样
LOG(INFO) << "This is INFO log item";
LOG(WARNING) << "This is WARNING log item";
LOG(ERROR) << "This is ERROR log item";
return 0;
}
\ No newline at end of file
flex_target(lex lexical_analyzer.l ${CMAKE_CURRENT_BINARY_DIR}/lexical_analyzer.c)
bison_target(syntax syntax_analyzer.y
${CMAKE_CURRENT_BINARY_DIR}/syntax_analyzer.c
DEFINES_FILE ${PROJECT_BINARY_DIR}/syntax_analyzer.h)
add_flex_bison_dependency(lex syntax)
add_library(syntax STATIC
${BISON_syntax_OUTPUTS}
${FLEX_lex_OUTPUTS}
)
include_directories(${PROJECT_BINARY_DIR})
add_executable(parser parser.c)
target_link_libraries(parser syntax common)
add_executable(lexer lexer.c)
target_link_libraries(lexer syntax common)
install(
TARGETS parser
RUNTIME DESTINATION bin
)
install(
TARGETS lexer
RUNTIME DESTINATION bin
)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<syntax_analyzer.h>
///
extern int lines;
extern int pos_start;
extern int pos_end;
///
extern FILE *yyin;
extern char *yytext;
extern int yylex();
// Mac-only hack.
YYSTYPE yylval;
///
int main(int argc, const char **argv) {
if (argc != 2) {
printf("usage: lexer input_file\n");
return 0;
}
const char *input_file = argv[1];
yyin = fopen(input_file, "r");
if (!yyin) {
fprintf(stderr, "cannot open file: %s\n", input_file);
return 1;
}
int token;
printf("%5s\t%10s\t%s\t%s\n", "Token", "Text", "Line", "Column (Start,End)");
while ((token = yylex())) {
printf("%-5d\t%10s\t%d\t(%d,%d)\n",
token, yytext,
lines, pos_start, pos_end);
}
return 0;
}
%option noyywrap
%{
/*****************声明和选项设置 begin*****************/
#include <stdio.h>
#include <stdlib.h>
#include "syntax_tree.h"
#include "syntax_analyzer.h"
int lines=1;
int pos_start=1;
int pos_end=1;
void pass_node(char *text){
yylval.node = new_syntax_tree_node(text);
}
/*****************声明和选项设置 end*****************/
%}
%x COMMENT
%%
/* to do for students */
/* two cases for you, pass_node will send flex's token to bison */
\+ {pos_start = pos_end; pos_end += 1; pass_node(yytext); return ADD;}
\- {pos_start = pos_end; pos_end += 1; pass_node(yytext); return SUB;}
\* {pos_start = pos_end; pos_end += 1; pass_node(yytext); return MUL;}
\/ {pos_start = pos_end; pos_end += 1; pass_node(yytext); return DIV;}
\< {pos_start = pos_end; pos_end += 1; pass_node(yytext); return LT;}
\<= {pos_start = pos_end; pos_end += 2; pass_node(yytext); return LTE;}
\> {pos_start = pos_end; pos_end += 1; pass_node(yytext); return GT;}
\>= {pos_start = pos_end; pos_end += 2; pass_node(yytext); return GTE;}
== {pos_start = pos_end; pos_end += 2; pass_node(yytext); return EQ;}
!= {pos_start = pos_end; pos_end += 2; pass_node(yytext); return NEQ;}
= {pos_start = pos_end; pos_end += 1; pass_node(yytext); return ASSIN;}
; {pos_start = pos_end; pos_end += 1; pass_node(yytext); return SEMICOLON;}
, {pos_start = pos_end; pos_end += 1; pass_node(yytext); return COMMA;}
/* TODO: phase1. 请在这里补充其他的词法规则 */
. { pos_start = pos_end; pos_end++; return ERROR; }
/****请在此补全所有flex的模式与动作 end******/
%%
#include "syntax_tree.h"
extern syntax_tree *parse(const char*);
int main(int argc, char *argv[])
{
syntax_tree *tree = NULL;
const char *input = NULL;
if (argc == 2) {
input = argv[1];
} else if(argc >= 3) {
printf("usage: %s <cminus_file>\n", argv[0]);
return 1;
}
// Call the syntax analyzer.
tree = parse(input);
print_syntax_tree(stdout, tree);
del_syntax_tree(tree);
return 0;
}
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "syntax_tree.h"
// external functions from lex
extern int yylex();
extern int yyparse();
extern int yyrestart();
extern FILE * yyin;
// external variables from lexical_analyzer module
extern int lines;
extern char * yytext;
extern int pos_end;
extern int pos_start;
// Global syntax tree
syntax_tree *gt;
// Error reporting
void yyerror(const char *s);
// Helper functions written for you with love
syntax_tree_node *node(const char *node_name, int children_num, ...);
%}
/* Complete this definition.
Hint: See pass_node(), node(), and syntax_tree.h.
Use forward declaring. */
%union {
struct _syntax_tree_node * node;
char * name;
}
/* Your tokens here. */
%token <node> ERROR
%token <node> ADD
%token <node> SUB
%token <node> MUL
%token <node> DIV
%token <node> LT
%token <node> LTE
%token <node> GT
%token <node> GTE
%token <node> EQ
%token <node> NEQ
%token <node> ASSIN
%token <node> SEMICOLON
%token <node> COMMA
%token <node> LPARENTHESE
%token <node> RPARENTHESE
%token <node> LBRACKET
%token <node> RBRACKET
%token <node> LBRACE
%token <node> RBRACE
%token <node> ELSE
%token <node> IF
%token <node> INT
%token <node> RETURN
%token <node> VOID
%token <node> WHILE
%token <node> IDENTIFIER
%token <node> INTEGER
%token <node> FLOAT
%token <node> FLOATPOINT // 这个是 float 类型的 token
//%token <node> EOL
//%token <node> BLANK
//%token <node> COMMENT
%type <node> program declaration-list declaration var-declaration type-specifier fun-declaration params param-list param compound-stmt local-declarations statement-list statement expression-stmt selection-stmt iteration-stmt return-stmt expression var simple-expression relop additive-expression addop term mulop factor integer float call args arg-list
/* compulsory starting symbol */
%start program
%%
/* Your rules here. TA has completed many */
program : declaration-list {$$ = node( "program", 1, $1); gt->root = $$;}
;
declaration-list : declaration-list declaration {$$ = node( "declaration-list", 2, $1, $2);}
| declaration {$$ = node( "declaration-list", 1, $1);}
;
declaration : var-declaration {$$ = node( "declaration", 1, $1);}
| fun-declaration {$$ = node( "declaration", 1, $1);}
;
var-declaration : type-specifier IDENTIFIER SEMICOLON {$$ = node( "var-declaration", 3, $1, $2, $3);}
| type-specifier IDENTIFIER LBRACKET INTEGER RBRACKET SEMICOLON {$$ = node( "var-declaration", 6, $1, $2, $3, $4, $5, $6);}
;
type-specifier : INT {$$ = node( "type-specifier", 1, $1);}
| FLOAT { $$ = node( "type-specifier", 1, $1); }
| VOID {$$ = node( "type-specifier", 1, $1);}
;
fun-declaration : type-specifier IDENTIFIER LPARENTHESE params RPARENTHESE compound-stmt {$$ = node( "fun-declaration", 6, $1, $2, $3, $4, $5, $6);}
;
params : param-list {$$ = node( "params", 1, $1);}
| VOID {$$ = node( "params", 1, $1);}
;
param-list : param-list COMMA param {$$ = node( "param-list", 3, $1, $2, $3);}
| param {$$ = node( "param-list", 1, $1);}
;
param : type-specifier IDENTIFIER {$$ = node( "param", 2, $1, $2);}
| type-specifier IDENTIFIER LBRACKET RBRACKET {$$ = node( "param", 4, $1, $2, $3, $4);}
;
compound-stmt : LBRACE local-declarations statement-list RBRACE {$$ = node( "compound-stmt", 4, $1, $2, $3, $4);}
;
local-declarations : local-declarations var-declaration {$$ = node( "local-declarations", 2, $1, $2);}
| {$$ = node( "local-declarations",0);}
;
statement-list : statement-list statement {$$ = node( "statement-list", 2, $1, $2);}
| {$$ = node( "statement-list",0);}
// TODO: phase1. 补充其他的文法产生式逻辑
%%
/// The error reporting function.
void yyerror(const char * s)
{
// TO STUDENTS: This is just an example.
// You can customize it as you like.
fprintf(stderr, "error at line %d column %d: %s\n", lines, pos_start, s);
}
/// Parse input from file `input_path`, and prints the parsing results
/// to stdout. If input_path is NULL, read from stdin.
///
/// This function initializes essential states before running yyparse().
syntax_tree *parse(const char *input_path)
{
if (input_path != NULL) {
if (!(yyin = fopen(input_path, "r"))) {
fprintf(stderr, "[ERR] Open input file %s failed.\n", input_path);
exit(1);
}
} else {
yyin = stdin;
}
lines = pos_start = pos_end = 1;
gt = new_syntax_tree();
yyrestart(yyin);
yyparse();
return gt;
}
/// A helper function to quickly construct a tree node.
///
/// e.g. $$ = node("program", 1, $1);
syntax_tree_node *node(const char *name, int children_num, ...)
{
syntax_tree_node *p = new_syntax_tree_node(name);
syntax_tree_node *child;
// 这里表示 epsilon结点是通过 children_num == 0 来判断的
if (children_num == 0) {
child = new_syntax_tree_node("epsilon");
syntax_tree_add_child(p, child);
} else {
va_list ap;
va_start(ap, children_num);
for (int i = 0; i < children_num; ++i) {
child = va_arg(ap, syntax_tree_node *);
syntax_tree_add_child(p, child);
}
va_end(ap);
}
return p;
}
#!/bin/sh
rm -rf output_student/*
rm -rf output_student_ast/*
#!/bin/bash
# DO NOT MODIFY!
# If you need customized behavior, please create your own script.
function run_tests() {
local TESTCASE_DIR=$1
local OUTPUT_DIR=$2
local OUTPUT_STD_DIR=$3
local score=0
local total=0
mkdir -p "$OUTPUT_DIR"
# 对每个 .cminus 文件生成 syntax_tree 文件
for testcase in "$TESTCASE_DIR"/*.cminus; do
filename="$(basename "$testcase")"
echo "[info] Analyzing $filename"
# 生成学生的 syntax_tree 文件
"$BUILD_DIR"/parser "$testcase" > "$OUTPUT_DIR/${filename%.cminus}.syntax_tree"
# 比较当前文件的输出与标准输出
if [[ ${2:-no} != "no" ]]; then
echo "[info] Comparing $filename..."
# 如果是详细模式
if [[ ${2:-no} == "verbose" ]]; then
diff "$OUTPUT_DIR/${filename%.cminus}.syntax_tree" "$OUTPUT_STD_DIR/${filename%.cminus}.syntax_tree"
else
diff -q "$OUTPUT_DIR/${filename%.cminus}.syntax_tree" "$OUTPUT_STD_DIR/${filename%.cminus}.syntax_tree"
fi
# 检查 diff 的返回值
if [ $? -eq 0 ]; then
echo "[info] $filename is correct!"
let score=score+1 # 正确时得分+1
else
echo "[info] $filename differs from the expected output."
fi
fi
let total=total+1 # 总文件数+1
rm -f "$CUR_DIR/${filename%.cminus}"
done
# 输出当前测试集的得分
echo "[info] Score for $TESTCASE_DIR: $score/$total"
return $score
}
# 检查命令行参数是否足够
if [[ $# -lt 1 ]]; then
echo "usage: ./eval_phase1.sh <input> [<summary>]"
echo " <input> can be one of 'easy', 'normal', 'hard', 'testcases_general', or '-all'."
echo " <summary> can be one of 'no', 'yes', and 'verbose'. the default value is 'no'"
exit 1
fi
CUR_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
BUILD_DIR="$CUR_DIR/../../build"
# 检查是否使用了 -all 选项
if [[ $1 == "-all" ]]; then
TOTAL_SCORE=0
TOTAL_FILES=0
# 定义四个测试集
TESTCASES=("easy" "normal" "hard" "testcases_general")
for TESTCASE in "${TESTCASES[@]}"; do
if [[ $TESTCASE == "testcases_general" ]]; then
TESTCASE_DIR="$CUR_DIR/../$TESTCASE"
else
TESTCASE_DIR="$CUR_DIR/input/$TESTCASE"
fi
OUTPUT_DIR="$CUR_DIR/output_student/$TESTCASE"
OUTPUT_STD_DIR="$CUR_DIR/output_standard/$TESTCASE"
# 计算有效文件数
VALID_FILES=$(find "$TESTCASE_DIR" -maxdepth 1 -name '*.cminus' | wc -l)
echo "[info] Found $VALID_FILES valid files in $TESTCASE_DIR"
run_tests "$TESTCASE_DIR" "$OUTPUT_DIR" "$OUTPUT_STD_DIR" $2
CURRENT_SCORE=$?
let TOTAL_SCORE+=CURRENT_SCORE
TOTAL_FILES=$(($TOTAL_FILES + $VALID_FILES))
done
# 输出总分
echo "[info] Total score for all testcases: $TOTAL_SCORE/$TOTAL_FILES"
else
# 单个测试集处理
TESTCASE="$1"
if [[ $TESTCASE == "easy" || $TESTCASE == "normal" || $TESTCASE == "hard" ]]; then
TESTCASE_DIR="$CUR_DIR/input/$TESTCASE"
elif [[ $TESTCASE == "testcases_general" ]]; then
TESTCASE_DIR="$CUR_DIR/../$TESTCASE"
fi
OUTPUT_DIR="$CUR_DIR/output_student/$TESTCASE"
OUTPUT_STD_DIR="$CUR_DIR/output_standard/$TESTCASE"
# 运行单个测试集
run_tests "$TESTCASE_DIR" "$OUTPUT_DIR" "$OUTPUT_STD_DIR" $2
fi
\ No newline at end of file
#!/bin/bash
# DO NOT MODIFY!
# If you need customized behavior, please create your own script.
function run_tests() {
local TESTCASE_DIR=$1
local OUTPUT_DIR=$2
local OUTPUT_STD_DIR=$3
local score=0
local total=0
mkdir -p "$OUTPUT_DIR"
# 对每个 .cminus 文件生成 ast 文件
for testcase in "$TESTCASE_DIR"/*.cminus; do
filename="$(basename "$testcase")"
# 检查文件名是否以 FAIL 开头,跳过该文件
if [[ "$filename" == FAIL* ]]; then
echo "[info] Skipping $filename (starts with FAIL)"
continue
fi
echo "[info] Analyzing $filename"
# 生成学生的 AST 文件
"$BUILD_DIR"/cminusfc "$testcase" > "$OUTPUT_DIR/${filename%.cminus}.ast"
# 比较当前文件的输出与标准输出
if [[ ${2:-no} != "no" ]]; then
echo "[info] Comparing $filename..."
# 如果是详细模式
if [[ ${2:-no} == "verbose" ]]; then
diff "$OUTPUT_DIR/${filename%.cminus}.ast" "$OUTPUT_STD_DIR/${filename%.cminus}.ast"
else
diff -q "$OUTPUT_DIR/${filename%.cminus}.ast" "$OUTPUT_STD_DIR/${filename%.cminus}.ast"
fi
# 检查 diff 的返回值
if [ $? -eq 0 ]; then
echo "[info] $filename is correct!"
let score=score+1 # 正确时得分+1
else
echo "[info] $filename differs from the expected output."
fi
fi
let total=total+1 # 总文件数+1
rm -f "$CUR_DIR/${filename%.cminus}"
done
# 输出当前测试集的得分
echo "[info] Score for $TESTCASE_DIR: $score/$total"
return $score
}
# 检查命令行参数是否足够
if [[ $# -lt 1 ]]; then
echo "usage: ./eval_phase2.sh <input> [<summary>]"
echo " <input> can be one of 'easy', 'normal', 'hard', 'testcases_general', or '-all'."
echo " <summary> can be one of 'no', 'yes', and 'verbose'. the default value is 'no'"
exit 1
fi
CUR_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
BUILD_DIR="$CUR_DIR/../../build"
# 检查是否使用了 -all 选项
if [[ $1 == "-all" ]]; then
TOTAL_SCORE=0
TOTAL_FILES=0
# 定义四个测试集
TESTCASES=("easy" "normal" "hard" "testcases_general")
for TESTCASE in "${TESTCASES[@]}"; do
if [[ $TESTCASE == "testcases_general" ]]; then
TESTCASE_DIR="$CUR_DIR/../$TESTCASE"
else
TESTCASE_DIR="$CUR_DIR/input/$TESTCASE"
fi
OUTPUT_DIR="$CUR_DIR/output_student_ast/$TESTCASE"
OUTPUT_STD_DIR="$CUR_DIR/output_standard_ast/$TESTCASE"
# 计算有效文件数,跳过以 FAIL 开头的文件
VALID_FILES=$(find "$TESTCASE_DIR" -maxdepth 1 -name '*.cminus' ! -name 'FAIL*' | wc -l)
echo "[info] Found $VALID_FILES valid files in $TESTCASE_DIR"
# 运行测试集并跳过以 FAIL 开头的文件
run_tests "$TESTCASE_DIR" "$OUTPUT_DIR" "$OUTPUT_STD_DIR" $2
CURRENT_SCORE=$?
let TOTAL_SCORE+=CURRENT_SCORE
TOTAL_FILES=$(($TOTAL_FILES + $VALID_FILES))
done
# 输出总分
echo "[info] Total score for all testcases: $TOTAL_SCORE/$TOTAL_FILES"
else
# 单个测试集处理
TESTCASE="$1"
if [[ $TESTCASE == "easy" || $TESTCASE == "normal" || $TESTCASE == "hard" ]]; then
TESTCASE_DIR="$CUR_DIR/input/$TESTCASE"
elif [[ $TESTCASE == "testcases_general" ]]; then
TESTCASE_DIR="$CUR_DIR/../$TESTCASE"
fi
OUTPUT_DIR="$CUR_DIR/output_student_ast/$TESTCASE"
OUTPUT_STD_DIR="$CUR_DIR/output_standard_ast/$TESTCASE"
# 运行单个测试集
run_tests "$TESTCASE_DIR" "$OUTPUT_DIR" "$OUTPUT_STD_DIR" $2
fi
\ No newline at end of file
/* unclosed comment
\ No newline at end of file
// cminus dont support comment like that
int main(void){
return 0;
}
\ No newline at end of file
/* unclosed function */
int main(void)
{
\ No newline at end of file
int a1;
int f1(void) {}
int f2(void) {}
/*Basic num part*/
int main(void){
a = 0;
x = 0.0;
x = 1.;
x = .1;
a = 1+1;
a = a-1;
x = x*1;
x = a/x;
return 0;
}
\ No newline at end of file
int a;
int f(void) {}
int g(void) {}
/*
I konw it's weird, even stupid, to code C like this. w(゚Д゚)w
HOWEVER, we have to use some tricky cases to test your answer.
*/
float GVAR;
void NeverEverDeclareLikeThis;
int GARRAY[2333];
void MyFuncA(int floatNum, float intNum, void voidNums[]){
int IKnowYouAreVoid;
return MyFuncB(IKnowYouAreVoid);
}
float MyFuncB(void){
int IAmVoid[0];
return MyFuncA(.0, 0, IAmVoid);
}
int main(void){
int a; int b; int c;
a = b = c = (85 == 84 + 0.4);
if(a = b){
GARRAY[ ( MyFuncB() ) ] = GARRAY[c = 1.*.1 == 1.1];
}else if (MyFuncC(NotDeclared)){
}else;
return 0.;
}
\ No newline at end of file
/* associativity and precedence */
int main(void)
{
a = b = c = 1 + 1 / 2 * 1 * (1 + 1 + 1 - 1 / 1) + 3 + 4 * 3;
}
int gcd (int u, int v) { /* calculate the gcd of u and v */
if (v == 0) return u;
else return gcd(v, u - u / v * v); /* v,u-u/v*v is equals to u mod v*/
}
int main(void) {
int x; int y; int temp;
x = 72;
y = 18;
if (x<y) {
temp = x;
x = y;
y = temp;
}
gcd(x,y);
return 0;
}
void move(int x, int y)
{
putint(x); putch(32); putint(y); putch(44); putch(32);
}
void hanoi(int n, int one, int two, int three)
{
if (n == 1)
move(one, three);
else {
hanoi(n - 1, one, three, two);
move(one, three);
hanoi(n - 1, two, one, three);
}
}
int main(void )
{
int n;
n = getint();
while (n > 0) {
hanoi(getint(), 1, 2, 3);
putch(10);
n = n - 1;
}
return 0;
}
/* else should be bound to the closest if */
int main(void)
{
if (1) {} else if (2) {} else {}
return 0;
}
/* this is the sample program in C- in the book "Compiler Construction" */
/* A program to perform selection sort on a 10 element array. */
int x[10];
int minloc ( int a[], int low, int high )
{ int i; int x; int k;
k = low;
x = a[low];
i = low + 1;
while (i < high)
{ if (a[i] < x)
{ x = a[i];
k = i; }
i = i + 1;
}
return k;
}
void sort( int a[], int low, int high)
{ int i; int k;
i = low;
while ( i < high-1)
{ int t;
k = minloc(a, i, high);
t = a[k];
a[k] = a[i];
a[i] = t;
i = i + 1;
}
}
void main(void)
{ int i;
i = 0;
while ( i < 10)
{ x[i] = input();
i = i + 1; }
sort(x, 0, 10);
i = 0;
while (i < 10)
{ output(x[i]);
i = i + 1; }
}
int main(void){
int a;
a = 1;
int b;
return 0;
}
\ No newline at end of file
int main(void) {
int array[1];
array[1] = 0;
return 0;
}
float foo(float a, float b[]) {
return 1;
}
int main(void) {
return 0;
}
/*Basic selection part*/
int main(void){
int a; int b;
a = 1;
b = 1;
if(a != b){
if(a == b);
else{
a = b;
}
}
return 0;
}
\ No newline at end of file
int main(void) {
int i; float j;
void v;
return 0;
}
/*
int main() {
int arr[100];
int i;
int sum;
i = 0;
sum = 0;
while (getint()) {
arr[i] = getint();
i = i + 1;
}*/
int main(void) {
int arr[100];
int i;
int sum;
i = 0;
sum = 0;
while (getint()) {
arr[i] = getint();
i = i + 1;
}
while (i) {
i = i - 1;
sum = sum + arr[i];
}
return sum - 79;
}
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--* epsilon
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--+ statement-list
| | | | | | | | | >--+ statement-list
| | | | | | | | | | >--+ statement-list
| | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | >--* 0
| | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | >--+ float
| | | | | | | | | | | | | | | | | | | | | | >--* 0.0
| | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | >--+ float
| | | | | | | | | | | | | | | | | | | | | >--* 1.
| | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | >--+ statement
| | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ float
| | | | | | | | | | | | | | | | | | | | >--* .1
| | | | | | | | | | | | | >--* ;
| | | | | | | | | | >--+ statement
| | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | >--* ;
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | >--* a
| | | | | | | | | | | | >--* =
| | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | >--* -
| | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | >--* ;
| | | | | | | | >--+ statement
| | | | | | | | | >--+ expression-stmt
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ var
| | | | | | | | | | | | >--* x
| | | | | | | | | | | >--* =
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | >--* *
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | >--* ;
| | | | | | | >--+ statement
| | | | | | | | >--+ expression-stmt
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ var
| | | | | | | | | | | >--* x
| | | | | | | | | | >--* =
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | >--* /
| | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | >--* x
| | | | | | | | | >--* ;
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration-list
| | | >--+ declaration-list
| | | | >--+ declaration
| | | | | >--+ var-declaration
| | | | | | >--+ type-specifier
| | | | | | | >--* int
| | | | | | >--* a
| | | | | | >--* ;
| | | >--+ declaration
| | | | >--+ fun-declaration
| | | | | >--+ type-specifier
| | | | | | >--* int
| | | | | >--* f
| | | | | >--* (
| | | | | >--+ params
| | | | | | >--* void
| | | | | >--* )
| | | | | >--+ compound-stmt
| | | | | | >--* {
| | | | | | >--+ local-declarations
| | | | | | | >--* epsilon
| | | | | | >--+ statement-list
| | | | | | | >--* epsilon
| | | | | | >--* }
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* g
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--* epsilon
| | | | | >--+ statement-list
| | | | | | >--* epsilon
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--* epsilon
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--* epsilon
| | | | | | >--+ statement
| | | | | | | >--+ expression-stmt
| | | | | | | | >--+ expression
| | | | | | | | | >--+ var
| | | | | | | | | | >--* a
| | | | | | | | | >--* =
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ var
| | | | | | | | | | | >--* b
| | | | | | | | | | >--* =
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ var
| | | | | | | | | | | | >--* c
| | | | | | | | | | | >--* =
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | | | | | >--* /
| | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | >--* 2
| | | | | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | | | | >--* *
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | | | >--* *
| | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | | | | >--* -
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | | | | | | | | >--* /
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | >--* 3
| | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | >--* 4
| | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | >--* *
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | >--* 3
| | | | | | | | >--* ;
| | | | | >--* }
This diff is collapsed.
This diff is collapsed.
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--* epsilon
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--* epsilon
| | | | | | | >--+ statement
| | | | | | | | >--+ selection-stmt
| | | | | | | | | >--* if
| | | | | | | | | >--* (
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | >--* 1
| | | | | | | | | >--* )
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | >--* {
| | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | >--* }
| | | | | | | | | >--* else
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ selection-stmt
| | | | | | | | | | | >--* if
| | | | | | | | | | | >--* (
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | >--* 2
| | | | | | | | | | | >--* )
| | | | | | | | | | | >--+ statement
| | | | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | | | >--* {
| | | | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | >--* }
| | | | | | | | | | | >--* else
| | | | | | | | | | | >--+ statement
| | | | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | | | >--* {
| | | | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | >--* }
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
This diff is collapsed.
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--+ local-declarations
| | | | | | | >--* epsilon
| | | | | | >--+ var-declaration
| | | | | | | >--+ type-specifier
| | | | | | | | >--* int
| | | | | | | >--* array
| | | | | | | >--* [
| | | | | | | >--* 1
| | | | | | | >--* ]
| | | | | | | >--* ;
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--* epsilon
| | | | | | | >--+ statement
| | | | | | | | >--+ expression-stmt
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ var
| | | | | | | | | | | >--* array
| | | | | | | | | | | >--* [
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | >--* ]
| | | | | | | | | | >--* =
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | >--* 0
| | | | | | | | | >--* ;
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration-list
| | | >--+ declaration
| | | | >--+ fun-declaration
| | | | | >--+ type-specifier
| | | | | | >--* float
| | | | | >--* foo
| | | | | >--* (
| | | | | >--+ params
| | | | | | >--+ param-list
| | | | | | | >--+ param-list
| | | | | | | | >--+ param
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* float
| | | | | | | | | >--* a
| | | | | | | >--* ,
| | | | | | | >--+ param
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* float
| | | | | | | | >--* b
| | | | | | | | >--* [
| | | | | | | | >--* ]
| | | | | >--* )
| | | | | >--+ compound-stmt
| | | | | | >--* {
| | | | | | >--+ local-declarations
| | | | | | | >--* epsilon
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--* epsilon
| | | | | | | >--+ statement
| | | | | | | | >--+ return-stmt
| | | | | | | | | >--* return
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | >--* 1
| | | | | | | | | >--* ;
| | | | | | >--* }
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--* epsilon
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--* epsilon
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--+ local-declarations
| | | | | | | >--+ local-declarations
| | | | | | | | >--* epsilon
| | | | | | | >--+ var-declaration
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* int
| | | | | | | | >--* a
| | | | | | | | >--* ;
| | | | | | >--+ var-declaration
| | | | | | | >--+ type-specifier
| | | | | | | | >--* int
| | | | | | | >--* b
| | | | | | | >--* ;
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--+ statement-list
| | | | | | | | | >--+ statement-list
| | | | | | | | | | >--* epsilon
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | >--* a
| | | | | | | | | | | | >--* =
| | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | >--* ;
| | | | | | | | >--+ statement
| | | | | | | | | >--+ expression-stmt
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ var
| | | | | | | | | | | | >--* b
| | | | | | | | | | | >--* =
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | >--* ;
| | | | | | | >--+ statement
| | | | | | | | >--+ selection-stmt
| | | | | | | | | >--* if
| | | | | | | | | >--* (
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | >--+ relop
| | | | | | | | | | | | >--* !=
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | >--* b
| | | | | | | | | >--* )
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | >--* {
| | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | >--+ selection-stmt
| | | | | | | | | | | | | | >--* if
| | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | | >--+ relop
| | | | | | | | | | | | | | | | | >--* ==
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | >--* b
| | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | | >--* else
| | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | | | | | | >--* {
| | | | | | | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | >--* b
| | | | | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | | | | >--* }
| | | | | | | | | | | >--* }
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--+ local-declarations
| | | | | | | >--+ local-declarations
| | | | | | | | >--+ local-declarations
| | | | | | | | | >--* epsilon
| | | | | | | | >--+ var-declaration
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* int
| | | | | | | | | >--* i
| | | | | | | | | >--* ;
| | | | | | | >--+ var-declaration
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* float
| | | | | | | | >--* j
| | | | | | | | >--* ;
| | | | | | >--+ var-declaration
| | | | | | | >--+ type-specifier
| | | | | | | | >--* void
| | | | | | | >--* v
| | | | | | | >--* ;
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--* epsilon
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
This diff is collapsed.
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* void
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--* epsilon
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--* epsilon
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration-list
| | | >--+ declaration
| | | | >--+ fun-declaration
| | | | | >--+ type-specifier
| | | | | | >--* void
| | | | | >--* test
| | | | | >--* (
| | | | | >--+ params
| | | | | | >--+ param-list
| | | | | | | >--+ param
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* int
| | | | | | | | >--* a
| | | | | >--* )
| | | | | >--+ compound-stmt
| | | | | | >--* {
| | | | | | >--+ local-declarations
| | | | | | | >--* epsilon
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--* epsilon
| | | | | | | >--+ statement
| | | | | | | | >--+ return-stmt
| | | | | | | | | >--* return
| | | | | | | | | >--* ;
| | | | | | >--* }
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* void
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--+ local-declarations
| | | | | | | >--* epsilon
| | | | | | >--+ var-declaration
| | | | | | | >--+ type-specifier
| | | | | | | | >--* int
| | | | | | | >--* a
| | | | | | | >--* ;
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--+ statement-list
| | | | | | | | | >--* epsilon
| | | | | | | | >--+ statement
| | | | | | | | | >--+ expression-stmt
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ var
| | | | | | | | | | | | >--* a
| | | | | | | | | | | >--* =
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | >--* 10
| | | | | | | | | | >--* ;
| | | | | | | >--+ statement
| | | | | | | | >--+ expression-stmt
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | >--* test
| | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | >--* )
| | | | | | | | | >--* ;
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* void
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--* epsilon
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--* epsilon
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--* ;
| | | | | >--* }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment