-
Notifications
You must be signed in to change notification settings - Fork 652
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 85063cf
Showing
251 changed files
with
27,135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.c linguist-language=Go |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright 2019 <chaishushan{AT}gmail.com>. All rights reserved. | ||
# Use of this source code is governed by a BSD-style | ||
# license that can be found in the LICENSE file. | ||
|
||
# | ||
# MnBook: Mini Markdown Book | ||
# https://github.com/wa-lang/mnbook | ||
# | ||
|
||
default: | ||
mnbook serve | ||
|
||
build: | ||
-rm book | ||
mnbook build | ||
-rm book/.gitignore | ||
-rm -rf book/.git | ||
|
||
deploy: | ||
-@make clean | ||
mnbook build | ||
-rm book/.gitignore | ||
-rm -rf book/.git | ||
-rm -rf book/examples | ||
|
||
cd book && git init | ||
cd book && git add . | ||
cd book && git commit -m "first commit" | ||
cd book && git branch -M gh-pages | ||
cd book && git remote add origin [email protected]:chai2010/go-ast-book.git | ||
cd book && git push -f origin gh-pages | ||
|
||
clean: | ||
-rm -rf book |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* Copyright 2019 <chaishushan{AT}gmail.com>. All rights reserved. */ | ||
/* Use of this source code is governed by a Apache */ | ||
/* license that can be found in the LICENSE file. */ | ||
|
||
/* simplest version of calculator */ | ||
|
||
%{ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
var idValueMap = map[string]int{} | ||
%} | ||
|
||
%union { | ||
value int | ||
id string | ||
} | ||
|
||
%type <value> exp factor term | ||
%token <value> NUMBER | ||
%token <id> ID | ||
|
||
%token ADD SUB MUL DIV ABS | ||
%token LPAREN RPAREN ASSIGN | ||
%token EOL | ||
|
||
%% | ||
calclist | ||
: // nothing | ||
| calclist exp EOL { | ||
idValueMap["_"] = $2 | ||
fmt.Printf("= %v\n", $2) | ||
} | ||
| calclist ID ASSIGN exp EOL { | ||
idValueMap["_"] = $4 | ||
idValueMap[$2] = $4 | ||
fmt.Printf("= %v\n", $4) | ||
} | ||
; | ||
|
||
exp | ||
: factor { $$ = $1 } | ||
| exp ADD factor { $$ = $1 + $3 } | ||
| exp SUB factor { $$ = $1 - $3 } | ||
; | ||
|
||
factor | ||
: term { $$ = $1 } | ||
| factor MUL term { $$ = $1 * $3 } | ||
| factor DIV term { $$ = $1 / $3 } | ||
; | ||
|
||
term | ||
: NUMBER { $$ = $1 } | ||
| ID { $$ = idValueMap[$1] } | ||
| ABS term { if $2 >= 0 { $$ = $2 } else { $$ = -$2 } } | ||
| LPAREN exp RPAREN { $$ = $2 } | ||
; | ||
|
||
%% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2019 <chaishushan{AT}gmail.com>. All rights reserved. | ||
# Use of this source code is governed by a Apache | ||
# license that can be found in the LICENSE file. | ||
|
||
run: | ||
make flex | ||
make goyacc | ||
|
||
@go fmt | ||
go run . | ||
|
||
flex: | ||
flex --prefix=yy --header-file=calc.lex.h -o calc.lex.c calc.l | ||
|
||
goyacc: | ||
goyacc -o calc.y.go -p "calc" calc.y | ||
|
||
clean: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* Copyright 2019 <chaishushan{AT}gmail.com>. All rights reserved. */ | ||
/* Use of this source code is governed by a Apache */ | ||
/* license that can be found in the LICENSE file. */ | ||
|
||
%option noyywrap | ||
|
||
%{ | ||
#include "tok.h" | ||
%} | ||
|
||
%% | ||
|
||
[_a-zA-Z]+ { return ID; } | ||
[0-9]+ { return NUMBER; } | ||
|
||
"+" { return ADD; } | ||
"-" { return SUB; } | ||
"*" { return MUL; } | ||
"/" { return DIV; } | ||
"|" { return ABS; } | ||
|
||
"(" { return LPAREN; } | ||
")" { return RPAREN; } | ||
"=" { return ASSIGN; } | ||
|
||
\n { return EOL; } | ||
[ \t] { /* ignore whitespace */ } | ||
. { return ILLEGAL; } | ||
|
||
%% | ||
|
Oops, something went wrong.