Skip to content

Instantly share code, notes, and snippets.

@satouuta
Last active December 21, 2015 12:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save satouuta/6308817 to your computer and use it in GitHub Desktop.
Save satouuta/6308817 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef struct{
int index;
int error;
} parse;
/* "var" name [= expr1] */
int vardef(string program, parse* option){
if(program.substr(option->index, 3) != "var"){
option->error = 1;
return 0;
}
int old_index = option->index;
option->index += 3;
string vname = name(program, option);
if(option->error){
option->index = old_index;
return 0;
}
if(program[option->index] != '='){
return 0; //TODO
}
option->index++;
int expr = expr1(program, option);
if(option->error){
option->index = old_index;
return 0;
}
return 0;//TODO
}
/* name = expr1 */
int vardef(string program, parse* option){
int old_index = option->index;
option->index += 3;
string vname = name(program, option);
if(option->error){
return 0;
}
if(program[option->index] != '='){
return 0; //TODO
}
option->index++;
int expr = expr1(program, option);
if(option->error){
option->index = old_index;
return 0;
}
return 0;//TODO
}
int while_stmt(string program, parse *option){
int old_index = option->index;
if(program.substr(option->index, 5) != "while"){
option->error = 1;
return 0;
}
option->index += 5;
int cond = expr1(program, option);
if(program[option->index] != ':'){
option->error = 1;
option->index = old_index;
return 0;
}
skips(program, option);
int stmt = block(program, option);
if(program.substr(option->index, 3) != "end"){
option->error = 1;
option->index = old_index;
return 0;
}
return 0;//TODO
}
int for_stmt(string program, parse* option){
int old_index = option->index;
if(program.substr(option->index, 3) != "for"){
option->error = 1;
return 0;
}
option->index += 3;
name(program, option);
if(program.substr(option->index, 2) != "in"){
option->error = 1;
option->index = old_index;
return 0;
}
option->index += 2;
int cond = expr1(program, option);
if(program[option->index] != ':'){
option->error = 1;
option->index = old_index;
return 0;
}
skips(program, option);
int stmt1 = block(program, option);
if(program.substr(option->index, 3) != "end"){
option->error = 1;
option->index = old_index;
return 0;
}
return 0;//TODO
}
/*
match [expr]:
if [expr1]:
[shori...]
if [expr2]:
[shori...]
else:
[shori...]
end
*/
int match_stmt(string program, parse* option){
int old_index = option->index;
if(program.substr(option->index, 5) != "match"){
option->error = 1;
return 0;
}
opthion->index += 5;
int expr;
if(program[2])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment